Swadhin Biswas Feat/federation (#82) · 8/19/2026
c0437ed
37 lines · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
import { getDatabase, schema } from "@/db";
import BaseLayout from "@/layouts/BaseLayout.astro";
import { eq } from "drizzle-orm";
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
import UserProfileView from "@/components/profile/UserProfileView.astro";
import ServerDirectoryBar from "@/components/profile/ServerDirectoryBar.astro";

const { owner: username } = Astro.params;
const db = getDatabase() as NodePgDatabase<typeof schema>;
const tab = Astro.url.searchParams.get("tab") || "overview";

// 1. Fetch User
const user = await db.query.users.findFirst({
  where: eq(schema.users.username, username!),
});

// 2. If not a user, check if it's an organization
if (!user) {
  const org = await db.query.organizations.findFirst({
    where: eq(schema.organizations.name, username!),
  });
  if (org) {
    return Astro.redirect(`/orgs/${org.name}`);
  }
  return Astro.redirect("/404");
}
---

<BaseLayout title={`${user.displayName || user.username} (${user.username})`}>
  <!-- Server-wide discovery bar for all users and organizations -->
  <ServerDirectoryBar currentUsername={user.username} />

  <!-- GitHub-Authentic User Profile View -->
  <UserProfileView user={user} tab={tab} />
</BaseLayout>